package com.qxy.dydemo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class ShowList extends AppCompatActivity {
    RecyclerView mRecyclerView;
    MyAdapter mMyAdapter ;
    List<News> mNewsList = new ArrayList<>();
    List<ShowItem> mShowItemsList = new ArrayList<>();
    private Button toTVListButton;
    private Button toMovieListButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_list);
        toTVListButton= (Button)findViewById(R.id.button);
        toMovieListButton= (Button)findViewById(R.id.button2);
        toTVListButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(ShowList.this,TVList.class);
                startActivity(intent);
            }
        });
        toMovieListButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(ShowList.this,MovieList.class);
                startActivity(intent);
            }
        });


        mRecyclerView = findViewById(R.id.recyclerView);
        // 构造一些数据
        for (int i = 0; i < 50; i++) {
            News news = new News();
            news.title = "标题" + i;
            news.content = "内容" + i;
            mNewsList.add(news);
        }

        for (int i = 0; i < 50; i++) {
            ShowItem showItem = new ShowItem();
            showItem.actors = "主演" + i;
            showItem.director = "导演" + i;
            showItem.hotness = "热度" +i;
            showItem.show_name = "名字" +i;
            showItem.show_name_eng = "英文名字" +i;
            mShowItemsList.add(showItem);
        }





        mMyAdapter = new MyAdapter();
        mRecyclerView.setAdapter(mMyAdapter);
        LinearLayoutManager layoutManager = new LinearLayoutManager(ShowList.this);
        mRecyclerView.setLayoutManager(layoutManager);



    }






    class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = View.inflate(ShowList.this, R.layout.showlist_item, null);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
          /*  News news = mNewsList.get(position);
            holder.mTitleTv.setText(news.title);
            holder.mTitleContent.setText(news.content);*/
            ShowItem showItem = mShowItemsList.get(position);
            holder.mShowName.setText(showItem.show_name);
            holder.mHotness.setText(showItem.hotness);
            holder.mShowNameEng.setText(showItem.show_name_eng);
            holder.mActor.setText(showItem.actors);
            holder.mDirector.setText(showItem.director);

        }

        @Override
        public int getItemCount() {
            return mShowItemsList.size();
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView mShowName;
        TextView mActor;
        TextView mDirector;
        TextView mShowNameEng;
        TextView mHotness;


        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            mShowName = itemView.findViewById(R.id.show1);
            mActor = itemView.findViewById(R.id.show2);
            mDirector= itemView.findViewById(R.id.show3);
            mShowNameEng= itemView.findViewById(R.id.show4);
            mHotness=itemView.findViewById(R.id.show5);
        }
    }
}


